package com.woniuxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.entity.Dish;
import com.woniuxy.entity.DishCategory;
import com.woniuxy.provider.DishCategoryProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 菜品类别Mapper接口
 */
public interface DishCategoryMapper extends BaseMapper<DishCategory> {
    @Select("select * from gfr_dish_category")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "dish_category_name", property = "dishCategoryName"),
            @Result(column = "status", property = "status"),
            @Result(column = "navable", property = "navable"),
            @Result(column = "sort", property = "sort"),
    })
    List<DishCategory> getAll();

    @SelectProvider(type = DishCategoryProvider.class, method = "getByCondition")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "dish_category_name",property = "dishCategoryName"),
            @Result(column = "navable",property = "navable"),
            @Result(column = "status",property = "status"),
    })
    List<DishCategory> getByCondition(DishCategory dishCategory);

    @Select("select * from gfr_dish_category where dish_category_name=#{dishCategoryName}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "dish_category_name", property = "dishCategoryName"),
            @Result(column = "status", property = "status"),
            @Result(column = "navable", property = "navable"),
            @Result(column = "sort", property = "sort"),
    })
    DishCategory getByName(String dishCategoryName);

    @UpdateProvider(type = DishCategoryProvider.class,method = "update")
    void update(DishCategory dishCategory);

    /**
     * 根据id删除类别,逻辑删除
     * @author wmy
     */
    @Update("update gfr_dish_category set status='n' where id=#{id}")
    void deleteById(int id);
}
